<!DOCTYPE html>
<html>
<head>
<title>房间详情</title>

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<link rel="stylesheet" type="text/css" href="css/homeStyle.css">
<link rel="stylesheet" type="text/css" href="css/detail.css">
<script type="text/javascript" src="js/homePage.js"></script>
<script type="text/javascript" src="js/jquery-1.11.1.js"></script>
<script type="text/javascript" src="js/cookie_util.js"></script>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="js/house.js"></script>

<script type="text/javascript">
    var userId = getCookie("userId");
    if(isNull(userId)){
        window.location.href="logIndex.html";
    }
    var houseId = getCookie("houseId");
    var houseUser = getCookie("houseUser");
    if(isNull(houseId)){
        alert("获取房间的详细信息出错,请重新查看");
        window.location.href="homePage.html";
    }
    $(function(){
        var userName = getCookie("userName");
        if(isNull(userName)){
            $("#logid").html(userId);
        }else{
            $("#logid").html(userName);
        }
        if(isNull(userId)){
            window.location.href="logIndex.html";
        }
        addCookie("showAllRoom","1",2);//用于在点击返回首页时,显示全部房间信息
        if(isNull(houseUser)){//查看房间详情
            houseUser=null;
        }
        //查询房间的历史账单
        $.ajax({
            url:"/HouseRent/acct/getAcctInfoByHouseUser.do",
            type:"post",
            data:{"houseId":houseId,"userId":houseUser},
            dataType:"json",
            success:function(result){
                console.log(result.detail);
                console.log(result.data.houseInfo);
                if("0000"==result.status){
                    var accts = result.data.acctInfo;
                    if(!isNull(accts)){//账单信息
                        $("#acctList").html("");
                        for(var i=0;i<accts.length;i++){
                            var acct = accts[i];
                            var fee_detail = "房租:"+acct.house_rent+"(含:"+acct.charge_reason+"),水费:"+acct.water_charge+",电费:"+acct.power_charge;
                            //<td>'+acct.acct_id+'</td>
                            var tr = '<tr><td>'+acct.acct_id+'</td><td>'+acct.tote_fee+'</td>'+
                                    '<td>'+acct.start_date+" 至 "+acct.end_date+'</td>'+
                                    '<td>'+deCodeAcctPayTag(acct.pay_tag)+'</td><td>'+fee_detail+'</td>';
                            if("0"==acct.pay_tag && acct.order_status!=3){
                                tr+='<td><input type="button" class="titlebut" onclick="optAcct(this)" value="收租" /></td></tr>';
                            }else{
                                tr+='<td><input type="button" class="titlebut" onclick="optAcct(this)" value="删除" /></td></tr>';
                            }
                            var $tr = $(tr);
                            $tr.data("acctId",acct.acct_id);
                            $("#acctList").append(tr);
                        }
                    }else{
                        $("#acctList").html("暂无账单");
                    }
                    var house = result.data.houseInfo;
                    if(!isNull(house)){
                        $("#show-img").html('<img src="'+house.house_pic+'" id="largerimg" width="400" height="400"/>');
                        $("#roomId").html(house.house_number);
                        var roomType = house.house_type.split("-");
                        $("#roomType").html(roomType[0]+"室"+roomType[1]+"厅"+roomType[2]+"厨"+roomType[3]+"卫");
                        $("#roomAddress").html(house.house_address+" "+house.detail_address);
                        //$("#openDate").val();
                        $("#custName").html(house.real_name);
                        if(isNull(house.real_name)){
                            $("#custName").html("暂无");
                        }
                        $("#custTel").html(house.link_phone);
                        if(isNull(house.real_name)){
                            $("#custTel").html("暂无");
                        }
                        var email = "";
                        if(!isNull(house.e_mail)){
                            email += house.e_mail+" ";
                        }else if(!isNull(house.qq)){
                            email += house.qq;
                        }
                        if(isNull(email)){
                            email = "暂无";
                        }
                        $("#custqq").html(email);
                        $("#roomGoods").html(house.house_goods);
                        //房间的费用信息
                        $("#guarantyFee").text(house.guaranty_fee+"元");
                        $("#houseRent").text(house.house_rent+"元/月");
                        $("#waterCharge").text(house.water_charge+"元/月");
                        $("#powerCharge").text(house.power_charge+"元/月");
                        //$("#roomnotice").val();
                        if("0"==house.can_use_tag){//使用中
                            $("#cancelroom").val("退订");
                        }else{
                            $("#cancelroom").val("入住");
                        }
                        $("#cancelroom").data("houseId",house.house_id);
                    }
                    
                }
            },
            error:function(){
                alert("系统异常,请稍后重试");
            }
        });
    });
    
    //入住和退订
    function checkInOrUnsubscribe(input){
        var houseId = $(input).data("houseId");
        var optType = $(input).val();
        if(isNull(houseId)){
            alert("获取订单信息异常");
            return;
        }
        if("退订"==optType){//退订
            $.ajax({
                url:"/HouseRent/order/endOrder.do",
                type:"post",
                data:{"houseId":houseId},
                dataType:"json",
                success:function(result){
                    alert(result.detail);
                    if("0000"==result.status){
                        window.location.href="homePage.html";
                    }
                }
            });
        }
        if("入住"==optType){
            addCookie("addCustHouseId",houseId,2);
            addCookie("addCust","1",2);
            window.location.href="homePage.html";
        }
    }
    
    //显示消息
    function showMsgs(showtag){
        //var userType=getCookie("userType");
        /*if("1"==showtag){
            addCookie("showMsg","1",2);
        }
        if("01"==userType){//房客
            window.location.href="personPage.html";
        }else{
            window.location.href="homePage.html";
        }*/
        addCookie("showMsg","1",2);
        window.location.href="homePage.html";
    }
</script>
</head>

<body style="margin:0px;">
	<!-- 右侧栏 -->
	<div class="detailPart">
		<div class="topnav">
			<a href="homePage.html" style="text-decoration: none;color:black;"><span id="fwczgl">房屋出租管理</span></a>
			<div id="navright">
				<span><img src="icon/mes.png" /> </span> <span><a href="Javascript:void(0)" onclick="showMsgs()">消息</a>
				</span> <span>|</span> <span><img src="icon/logper.png" /> </span> <span
					id="logid">测试人员</span> <span>|</span> <span><a href="Javascript:void(0)" onclick="logOut()">退出登录</a>
				</span>
			</div>
		</div>
		<div id="room-detail"><span>房间概况</span></div>
		<div class="content-detail">
				<div class="detail-img">
					<div id="show-img">
						<!-- <img src="img/background.png" id="largerimg" width="400" height="400"/> --> 
					</div>
				</div>
				<div class="detail-list">
					<div id="show-list">
					<!-- <h3 id="safetitle">大奖赛卡拉胶抵抗力撒娇了靠的就是卡了</h3><br/> -->
					<span class="spandetail">房间号：</span><span class="spanvalue" id="roomId"></span>
					<span class="spandetail">房间类型：</span><span class="spanvalue" id="roomType"></span><br/>
					<span class="spandetail">房间地址：</span><span class="spanvalue" id="roomAddress"></span><br/>
					<!-- <span class="spandetail">入住时间：</span><span class="spanvalue" id="openDate">2015-12-12</span> -->
					<span class="spandetail">入住人：</span><span class="spanvalue" id="custName"></span><br/>
					<span class="spandetail">联系方式：</span><span class="spanvalue" id="custTel"></span>
					<span class="spandetail">QQ/邮箱：</span><span class="spanvalue" id="custqq"></span><br/>
					<span class="spandetail">房间物品：</span><span class="spanvalue" id="roomGoods"></span><br/>
                    <span class="spandetail">房租：</span><span class="spanvalue" id="houseRent"></span><br/>
                    <span class="spandetail">水费：</span><span class="spanvalue" id="waterCharge"></span><br/>
                    <span class="spandetail">电费：</span><span class="spanvalue" id="powerCharge"></span><br/>
                    <span class="spandetail">入住所需押金：</span><span class="spanvalue" id="guarantyFee"></span><br/>
					<!-- <span class="spandetail">说明：</span><span class="spanvalue" id="roomnotice"></span><br/> -->
					<input type="button" id="cancelroom"  value="" onclick="checkInOrUnsubscribe(this)"/>
					</div>
				</div>
			</div>
		<div id="room-detail"><span>历史账单</span></div>
		<div class="room_mlist">
			<table>
				<thead>
					<tr>
						<td>账单号</td>
						<td>账单金额</td>
						<td>账单日期</td>
						<td>账单状态</td>
						<td>明细</td>
                        <td>操作</td>
					</tr>
				</thead>
				<tbody id="acctList"></tbody>
			</table>
		</div>
	</div>
</body>
</html>
